<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/4
 * Time: 16:53
 */
namespace app\admin\model;

use think\Model;
use think\Session;

class Admin extends Model{

    protected $name="admin";
        /**
         * 商家用户登录
         * @param $data
         * @return bool
         * @throws \think\db\exception\DataNotFoundException
         * @throws \think\db\exception\ModelNotFoundException
         * @throws \think\exception\DbException
         */
        public function login($data)
        {
            $user = self::useGlobalScope(false)->where([
                'username' => $data['username'],
            ])->find();
            if (!$user) {
                $this->error = '登录失败, 用户名不存在';
                return false;
            }
            if($user['password']!=md5($data['password'].$user['salt'])){
                $this->error = '登录失败, 密码错误';
                return false;
            }
            // 保存登录状态
            session("admin",$user);
            return true;
        }

}